
var sortColors = function(nums: number[]) {
    enum Colors { Red = 0, White = 1, Blue = 2 }

    var redTail = -1
    var blueHead = nums.length
    var i = 0
    while(i < blueHead) {
        if (nums[i] === Colors.White) {
            i++
            continue
        }
        else if (nums[i] === Colors.Red) {
            nums[i] = nums[redTail + 1]
            nums[redTail + 1] = Colors.Red
            redTail++
            i++
        }
        else if (nums[i] === Colors.Blue) {
            nums[i] = nums[blueHead - 1]
            nums[blueHead - 1] = Colors.Blue
            blueHead--
        }
    }
};

var input75: Array<number>;

input75 = [2,0]
sortColors(input75)
console.assert( input75.join(',') === '0,2')

input75 = [2]
sortColors(input75)
console.assert( input75.join(',') === '2')

input75 = [1,0]
sortColors(input75)
console.assert( input75.join(',') === '0,1')
